// pages/my/addStock/addStock.js
var app = getApp()
Page({
  data: {
    goodsInfoShow:true,
    tab:0,
    storageGoods: []
  },
  noStorageGoodsTap:function(event){
      this.setData({
        tab:0
      })
      this.getOrderList(0)
  },
  storageGoodsTap: function (event) {
    this.setData({
      tab: 1
    })
    this.getOrderList(1)
  },
  //加入库存
  addToStockTap:function(e){
    let data = {
      orderId:e.currentTarget.dataset.id
    }
    app.request('wx_app/agent_order/addSkuInfo',data,'GET').then(res=>{
      console.log(res)
      if (res.code==1) {
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 2000
        })
        this.getOrderList(0)
      }
    })
  },
  watchStockTap:function(event){
    wx.switchTab({
      url: '../../stock/stock',
    })
  },
  onLoad: function (options) {
    app.getMemInfo().then(res=>{
      this.setData({
        agentId:res.data.agentId,
        accountId:res.data.id
      })
      this.getOrderList(0)
    })
  },
  getOrderList(storeState){
    let data = {
      agentId:this.data.agentId,
      accountId:this.data.accountId,
      orderState:4,
      storeState
    }
    app.request('wx_app/agent_order/getStoredOrderList',data,'GET').then(res=>{
        let storageGoods = []
        if (res.data.orders) {        
          res.data.orders.forEach(item=>{
            storageGoods.push(item)
          })
          console.log(storageGoods)
          this.setData({
            storageGoods
          })
        }else{
          this.setData({
            storageGoods:[]
          })
        }

    })
  }
})